package com.songcan.common.serializer;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
import com.songcan.common.contans.CoreContants;
import com.songcan.common.exception.AuthException;
import lombok.SneakyThrows;

import java.io.IOException;

public class Auth2ExceptionSerializer extends StdSerializer<AuthException> {

    public Auth2ExceptionSerializer() {
        super(AuthException.class);
    }

    @Override
    @SneakyThrows
    public void serialize(AuthException e, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) {
        jsonGenerator.writeStartObject();
        jsonGenerator.writeStringField("code",CoreContants.ERROR_TOKEN_INVALID);
        jsonGenerator.writeStringField("msg", e.getMessage());
        jsonGenerator.writeStringField("data", e.getCode());
        jsonGenerator.writeEndObject();
    }


}
